package org.codetranslators.common;

/**
 * This class is a wrapper class around a node. It contains the node object and adds additional functionality
 * to a spanning tree node, namely the depth number and whether the node has been visited. 
 * 
 * It conforms to the Decorator design pattern (also known as Wrapper pattern).
 * @author shreesha123
 *
 */

public class SpanningTreeNode extends TreeNode{
	
	private TreeNode node;        // The contained node
	private Node graphNode;       // The node in the graph corresponding to this tree node
	private boolean visited;  // Indicates whether this node has been visited
	private int depthNumber;  // The depth number at which this node has been visited
	
	public SpanningTreeNode(TreeNode node, Node graphNode){
		this.node = node;
		this.graphNode = graphNode;
	}

	public void setVisited(boolean visited){
		this.visited = visited;
	}
	
	public void setDepthNumber(int num){
		this.depthNumber = num;
	}
	
	public int getDepthNumber(){
		return depthNumber;
	}

	public boolean isVisited() {
		return visited;
	}
	
	public Node getGraphNode(){
		return graphNode;
	}
	
	public void display(){
		System.out.print("Node: " + node.getName() +  " Depth First number = " + depthNumber + " Children = ");
		int numNodes = children.size();
		for(int i = 0; i < numNodes; i++){
			SpanningTreeNode node = (SpanningTreeNode) children.elementAt(i);
			System.out.print(node.getName() + ", ");
		}
		System.out.println("");
		for(int j = 0; j < numNodes; j++){
			SpanningTreeNode node = (SpanningTreeNode) children.elementAt(j);
			node.display();
		}
	}
}
